import request from "@/utils/request";
import { AxiosPromise } from "axios";
import {
  AllocateQuery,
  AllocatePageResult,
  CreateForm,
  CreateResult,
  AllocateDetailResult,
  VisitItem,
  BanquetItem,
  MemberItem,
  DashboardCustomer,
} from "./types";

/**
 * 获取跟进记录
 * @param queryParams
 */
export function getAllocatePage(
  queryParams?: AllocateQuery
): AxiosPromise<AllocatePageResult> {
  return request({
    url: "/api/customer.allocate/index",
    method: "get",
    params: queryParams,
  });
}

/**
 * 添加客资
 * @param postData
 */
export function createCustomer(
  postData: CreateForm
): AxiosPromise<CreateResult> {
  return request({
    url: "/api/customer.member/add",
    method: "post",
    data: postData,
  });
}

/**
 * 获取客资详情
 * @param id
 */
export function getAllocateDetails(
  id: number
): AxiosPromise<AllocateDetailResult> {
  return request({
    url: "/api/customer.allocate/details/id/" + id,
    method: "get",
  });
}

/**
 * 获取回访状态
 */
export function getStatusPicker(): AxiosPromise<DictType[]> {
  return request({
    url: "/api/system.status/picker",
    method: "get",
  });
}

// 添加回访记录
export function addAllocateRecord(
  memberId: number,
  allocateId: number,
  postData: VisitItem
) {
  return request({
    url:
      "/api/customer.visit/append/member_id/" +
      memberId +
      "/allocate_id/" +
      allocateId,
    method: "post",
    data: postData,
  });
}

// 更新婚宴信息
export function updateBanquetInfo(
  memberId: number,
  allocateId: number,
  postData: BanquetItem
) {
  return request({
    url:
      "/api/customer.product/update/member_id/" +
      memberId +
      "/allocate_id/" +
      allocateId,
    method: "post",
    data: postData,
  });
}

// 更新客资信息
export function updateCustomerInfo(
  memberId: number,
  allocateId: number,
  postData: MemberItem
) {
  return request({
    url:
      "/api/customer.member/edit/member_id/" +
      memberId +
      "/allocate_id/" +
      allocateId,
    method: "post",
    data: postData,
  });
}

// 分配客户
export function shareCustomer(
  memberId: number,
  allocateId: number,
  postData: any
) {
  return request({
    url:
      "/api/customer.allocate/share/member_id/" +
      memberId +
      "/allocate_id/" +
      allocateId,
    method: "post",
    data: postData,
  });
}

// 获取dashboard 的数据,返回的是一个对象，包含了total,unfollow,valid, unconnect
export function getDashboardData(): AxiosPromise<DashboardCustomer> {
  return request({
    url: "/api/customer.allocate/dashboard",
    method: "get",
  });
}
